package hr.aspect;

import hr.entity.DO.EmployeeMovementDO;
import hr.entity.MovementLog;
import hr.mapper.MovementLogMapper;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 岗位调动日志记录处理
 */
@Aspect
@Component
public class MovementLogAspect {

    @Autowired
    private MovementLogMapper movementLogMapper;

    /**
     * 处理完请求前执行
     */
    @Before(value = "execution(* hr.controller.EmployeemovementController.departmentPostMovement(..)) " +
            "&& " + "args(movementDO)", argNames = "movementDO")
    public void logPositionMovement(@RequestBody EmployeeMovementDO movementDO) {
        MovementLog movementLog = new MovementLog();
        movementLog.setName(movementDO.getName());
        movementLog.setFromDepartmentName(movementDO.getFromDepartmentName());
        movementLog.setToDepartmentName(movementDO.getToDepartmentName());
        movementLog.setFromPositionName(movementDO.getFromPositionName());
        movementLog.setToPositionName(movementDO.getToPositionName());
        movementLog.setMovementDate(movementDO.getMovementDate());
        movementLogMapper.insert(movementLog);
    }
}
